package com.htfyun.ft.device;

import com.htfyun.ft.config.NVRomKeysAttr;
import com.htfyun.ft.utils.SystemPropertyUtil;


public enum DeviceAttr {

    unknown("unknown", NVRomKeysAttr.values()),
    kar_pro("kar_pro", getNVRomKeysAttrForKarPro()),
    S9("S9", getNVRomKeysAttrForS9()),

    ;
    private final String product;
    private final NVRomKeysAttr[] supportedNVRomKeyAttrs;

    DeviceAttr(String product, NVRomKeysAttr[] nvromKeys) {
        this.product = product;
        supportedNVRomKeyAttrs = nvromKeys;
    }

    public static boolean isNVRomKeySupported(NVRomKeysAttr key) {

        if (key == null) {
            return false;
        }

        DeviceAttr attr = getRunningDeviceAttr();
        if (null == attr.supportedNVRomKeyAttrs) {
            return false;
        }

        for (NVRomKeysAttr k : attr.supportedNVRomKeyAttrs) {
            if (k == key) {
                return true;
            }
        }
        return false;
    }

    private static NVRomKeysAttr[] getNVRomKeysAttrForKarPro() {
        return new NVRomKeysAttr[]{
                NVRomKeysAttr.screen,
                NVRomKeysAttr.headset,
                NVRomKeysAttr.finger_tp,
                NVRomKeysAttr.camera,
                NVRomKeysAttr.keys,
                NVRomKeysAttr.led_breath,
                NVRomKeysAttr.mic_6_channel,
                NVRomKeysAttr.unisound_mic_test,
                NVRomKeysAttr.speaker,
                NVRomKeysAttr.battery,
                NVRomKeysAttr.bluetooth,
                NVRomKeysAttr.wifi,
                NVRomKeysAttr.sdcard,
                NVRomKeysAttr.ram_rom,
                NVRomKeysAttr.hall_sensor,
                NVRomKeysAttr.light_sensor,
                NVRomKeysAttr.proximity_sensor,
                NVRomKeysAttr.accelerate_sensor,
                NVRomKeysAttr.servo,

                NVRomKeysAttr.info_ft_test,

                NVRomKeysAttr.bsn,
                NVRomKeysAttr.sn,
                NVRomKeysAttr.wmac,
                NVRomKeysAttr.user,
                NVRomKeysAttr.pc_checked,

                NVRomKeysAttr.aging_emmc,
                NVRomKeysAttr.aging_cpu,

        };
    }

    private static NVRomKeysAttr[] getNVRomKeysAttrForS9() {
        return new NVRomKeysAttr[] {
                NVRomKeysAttr.screen,
                NVRomKeysAttr.headset,
                NVRomKeysAttr.finger_tp,
                NVRomKeysAttr.camera,
                NVRomKeysAttr.keys_android,
//                NVRomKeysAttr.led_breath,
//                NVRomKeysAttr.mic_6_channel,
                NVRomKeysAttr.mic_2_channel,
                NVRomKeysAttr.speaker,
                NVRomKeysAttr.battery,
                NVRomKeysAttr.bluetooth,
                NVRomKeysAttr.wifi,
//                NVRomKeysAttr.sdcard,
                NVRomKeysAttr.ram_rom,
                NVRomKeysAttr.hall_sensor,
                NVRomKeysAttr.light_sensor,
                NVRomKeysAttr.proximity_sensor,
                NVRomKeysAttr.accelerate_sensor,
//                NVRomKeysAttr.servo,
                NVRomKeysAttr.led_rgb,

                NVRomKeysAttr.hard_disk,
                NVRomKeysAttr.white_list_install,
                NVRomKeysAttr.white_list_uninstall,
                NVRomKeysAttr.white_list_net,
                NVRomKeysAttr.night_display,
                NVRomKeysAttr.type_c,

                NVRomKeysAttr.info_ft_test,

                NVRomKeysAttr.sn,
//                NVRomKeysAttr.wmac,

                NVRomKeysAttr.aging_emmc,
                NVRomKeysAttr.aging_cpu,
        };
    }

    private static DeviceAttr runningDeviceAttr = null;
    private static DeviceAttr getRunningDeviceAttr() {
        if (runningDeviceAttr != null) {
            return runningDeviceAttr;
        }
        runningDeviceAttr = unknown;
        final String product = SystemPropertyUtil.getSystemProperty("ro.build.product");
        for (DeviceAttr deviceAttr : DeviceAttr.values()) {
            if (deviceAttr.product != null && deviceAttr.product.equalsIgnoreCase(product)) {
                runningDeviceAttr = deviceAttr;
                break;
            }
        }
        return runningDeviceAttr;

    }
}
